//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>
#include <elatypes.h>

EXTERN_C char * CDECL strncpy(char *dst, const char *src, size_t n)
{
#ifdef _GNUC

#if defined(_x86)
    int temp0, temp1, temp2, temp3;
    ASM(
        "1:"
        "decl %2;"
        "js 2f;"
        "lodsb;"
        "stosb;"
        "testb %%al,%%al;"
        "jne 1b;"
        "rep;"
        "stosb;"
        "2:"
        :"=D" (temp0), "=S" (temp1),  "=c" (temp2), "=a" (temp3)
        :"0" (dst), "1" (src), "2" (n)
        :"memory");
    return dst;
#endif   //if defined(_x86)

#endif    //ifdef _GNUC

    char *d;
    if (!dst || !src)
        return (dst);
    d = dst;
    for (; n && *src; d++, src++, n--)
        *d = *src;
    while (n--)
        *d++ = '\0';
    return (dst);
}
